# encoding: utf-8
from flask import request
from app import db
from . import api, Resource
from flask_login import current_user
from .authentication import login_required
from ..models import Friend

class FriendAdd(Resource):
    @login_required
    def post(self):
        from_user_id = current_user.id
        to_user_id = request.form.get("id")
        friend = Friend(from_user_id=from_user_id, to_user_id=to_user_id)
        # 添加到数据库
        print(friend.status)
        db.session.add(friend)
        db.session.commit()
        return {"code": 0, "result": ""}

api.add_resource(FriendAdd, "/friend/add")


